<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.js"></script>
  <div id="box">
    {{content}}
    <br>
    {{num}}

    <hr>
    <!--绑定点击事件
    1.v-on:click="事件名"
    2.@:click="事件名"
    3.处理函数可以传递参数
    -->
    <button v-on:click="num++">v-on:事件名</button>
    <button @click="num++">简写:@事件名</button>
    <button @click="btn(10)">@事件名(实参)</button>
    <button @click="btn1">清空数字</button>
    <hr>
    <button @click="show">点击让h1显示和隐藏</button>
    <h1 v-show="flag">我是h1标签</h1>

  </div>
  <script>
    new Vue({
      el: '#box',
      data: {
        content: 'hello Vue',
        num: 10,
        flag: true
      },
      //函数统一定义在methods中
      methods: {
        btn(num) {
          this.num += num
        },
        btn1(num) {
          this.num = 0
        },
        show() {
          // this.flag = !this.flag
          // if (this.flag) {
          //   this.flag = false
          // } else {
          //   this.flag = true
          // }
          this.flag = this.flag ? false : true

        }
      }
    })
  </script>
</body>